package org.thunms.framework.license;


import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;

import org.thunms.framework.license.base64.Base64;

public class KeyGenerater {
	 private byte[] priKey; 

	 private byte[] pubKey; 

	 public void generater() { 
	  try { 

	  KeyPairGenerator keygen = KeyPairGenerator .getInstance("RSA"); 

	   SecureRandom secrand = new SecureRandom(); 

	   secrand.setSeed("www.川江号子.cn".getBytes()); // 初始化随机产生器 

	   keygen.initialize(2048, secrand); 

	   KeyPair keys = keygen.genKeyPair(); 

	   PublicKey pubkey = keys.getPublic(); 

	   PrivateKey prikey = keys.getPrivate();

	   pubKey = Base64.encode(pubkey.getEncoded()); 

	   priKey = Base64.encode(prikey.getEncoded()); 

	   System.out.println("pubKey(公匙) = " + new String(pubKey)); 

	   System.out.println("priKey (私匙) = " + new String(priKey)); 

	  } catch (java.lang.Exception e) { 

	   System.out.println("生成密钥对失败"); 

	   e.printStackTrace(); 

	  } 

	 } 

	 public byte[] getPriKey() { 

	  return priKey; 

	 } 

	 public byte[] getPubKey() { 

	  return pubKey; 

	 } 
public static void main(String[] args) {
	KeyGenerater key=new KeyGenerater();
	key.generater();
	System.out.println("对wanglp信息进行签名认真");
	byte[] sign=Signaturer.sign(key.getPriKey(), "wanglp");
	System.out.println("==签名认证信息====>>"+new String(sign));
	
	System.out.println("===验证==》"+SignProvider.verify(key.getPubKey(), "wanglp", sign));
}
}
